//
//  UICollectionView+ADUtil.m
//  ADKit
//
//  Created by jiangwei on 2018/4/24.
//

#import "UICollectionView+ADUtil.h"

@implementation UICollectionView (ADUtil)

- (void)ad_registerCell:(Class)cls {
    [self registerClass:cls forCellWithReuseIdentifier:NSStringFromClass(cls)];
}

- (void)ad_registerNibCell:(Class)cls {
    [self ad_registerNibCell:cls forCellReuseIdentifier:NSStringFromClass(cls)];
}

- (void)ad_registerNibCell:(Class)cls forCellReuseIdentifier:(NSString *)reuseIdentifier {
    [self registerNib:[UINib nibWithNibName:[NSStringFromClass(cls) componentsSeparatedByString:@"."].lastObject bundle:nil] forCellWithReuseIdentifier:reuseIdentifier];
}

- (void)ad_registerHeader:(Class)cls {
    [self registerClass:cls forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass(cls)];
}

- (void)ad_registerNibHeader:(Class)cls {
    [self ad_registerNibHeader:cls forCellReuseIdentifier:NSStringFromClass(cls)];
}

- (void)ad_registerNibHeader:(Class)cls forCellReuseIdentifier:(NSString *)reuseIdentifier {
    [self registerNib:[UINib nibWithNibName:[NSStringFromClass(cls) componentsSeparatedByString:@"."].lastObject bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdentifier];
}

- (void)ad_registerFooter:(Class)cls {
    [self registerClass:cls forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass(cls)];
}

- (void)ad_registerNibFooter:(Class)cls {
    [self ad_registerNibFooter:cls forCellReuseIdentifier:NSStringFromClass(cls)];
}

- (void)ad_registerNibFooter:(Class)cls forCellReuseIdentifier:(NSString *)reuseIdentifier {
    [self registerNib:[UINib nibWithNibName:[NSStringFromClass(cls) componentsSeparatedByString:@"."].lastObject bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:reuseIdentifier];
}

@end

@implementation UICollectionViewCell (ADUtil)

+ (NSString *)ad_cellReuseIdentifier {
    return NSStringFromClass(self);
}

@end

@implementation UICollectionReusableView (ADUtil)

+ (NSString *)ad_headerReuseIdentifier {
    return NSStringFromClass(self);
}

+ (NSString *)ad_footerReuseIdentifier {
    return NSStringFromClass(self);
}

@end
